<template>
	<view class="content" >
		   <form @submit="submit">
			<u-navbar :is-back="true" :border-bottom="false">
				<view style="height: 10px;"></view>
				<view  class="slot-wrap disfr-lr p15 f32" style="width: 100%;">
					<view class="slot-wrap-left"></view>
					<view class="slot-wrap-center mt10">商机置顶</view>
					<view class="slot-wrap-right pr">
						<!--<button form-type="submit" style="height: 70rpx;background: none;">
							<view style="position: relative;top:-20rpx;">
								<u-icon name="duihao" custom-prefix="qxl-icon" size="44"></u-icon>
							</view>
						</button>-->
					</view>
				</view>
			</u-navbar>

			<view v-if="show_main" class="main" >
				<view class="bgf p30 disfr-lr">
					<view>推荐标题</view>
					<view>{{result.opportunity.title}}</view>
				</view>
				<view class="bgf p30 disfr-lr bto">
					<view>商机ID</view>
					<view @click="copy" :data-text="result.opportunity.id">
					  {{result.opportunity.id}}
					  <u-icon name="fuzhi" custom-prefix="qxl-icon" size="30" style="position: relative;top:-3rpx;left:-5rpx;"></u-icon>
					</view>
				</view>
				<!--<view class="bgf p30">
					<view class="b">
						{{result.opportunity.title}}
					</view>
					<view class="disfr-lr f30 mt30">
						<view>
							<u-icon name="huo" custom-prefix="qxl-icon" color="red" size="44"></u-icon>
							<text>已推荐值:{{result.opportunity.coin_orders}}</text>
						</view>
						<view>有效期:{{result.opportunity.coin_expire_time ? result.opportunity.coin_expire_time : '未推荐'}}</view>
					</view>
					<view class="mt20">
						<view>
							我的{{result.virtual_coin_name}} <text class="f60" style="color: red;">{{result.user_virtual_coin}}</text>
						</view>
					</view>
				</view>
			   
				
				<view class="bgf p30 f32  bto">
					<radio-group name="meal_id">
						<view v-for="(item,index) in result.list" :key="index" :class="'disf f30 '+(index > 0 ? 'mt30' : '')" style="width: 100%;">
							<view v-for="item2 in item" :key="item2.id" style="width: 50%;">
								<label class="disf">
								   <radio :value="item2.id" style="transform:scale(0.7);position: relative;top:-5rpx;" color="#2979ff"/>
								   <view class="pr" style="left:-3rpx;">
									   <view>{{item2.name}}</view>
									   <view class="col999 f28">需要消耗{{result.virtual_coin_name}}({{item2.coin_num}})</view>
								   </view>
								</label>
							</view>
						</view>
					</radio-group >
				</view>-->
                <input type="text" :value="result.opportunity.id" name="opportunity_id" class="hide"/>
				<view style="height:50rpx;"></view>
				<view class="p30" style="width: 100%;text-align: center;">
					<rich-text :nodes="result.virtual_sels_depict"></rich-text>
					
					<view style="height: 10px;"></view>
					<view v-if="result.oh_signal.length > 0">
						<view v-for="(item,index) in result.oh_signal" :data-number="item" @click="service" class="custom-min-button mt30" 
						style="border-radius: 6px;margin-right: 20px;">
							<u-icon name="lianxiduifang" custom-prefix="qxl-icon" size="38"></u-icon>
							<text class="pr" style="top:-5rpx;">联系客服({{index+1}})</text>
						</view>
					</view>
				</view>
			</view>
			
		</form>
		<loading :loading="not_load"/><!--加载状态-->
	</view>
</template>

<script setup>
import { onLoad, onShow, onHide, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
import { ref } from 'vue';	
const show_main=ref(false);
const not_load=ref(false);
const result=ref({});
const group_id=ref(0); //推荐群ID

//表单提交
const submit=async(e)=>{
	if(!not_load.value) return;
	let form=e.detail.value;
	if(!form.meal_id){
		uni.$utils.showToast('请选择置顶值');
		return;
	}
	//console.log(form);return;
	not_load.value=false;
	let ret=await uni.$get('/appapi-opportunity-sendmeal',form);
	not_load.value=true;
	if(ret.error_code != 0){
		uni.$utils.showToast(ret.info);
		return;
	}
	uni.$utils.showToast(ret.info,0,()=>{
		uni.navigateBack({data:1});
	});
};
//页面加载时
onLoad(async (options)=>{
	//options.opportunity_id=10
	//group_id.value=options.id;
    loadPage(options,false);
});
//页面显示时执行
onShow(()=>{
	//console.log('语法糖onShow');
});
//页面隐藏时执行
onHide(()=>{
	//console.log('语法糖onHide');
});
/**
 * 加载接口数据
 * @param {Object} options  参数,对像数组
 * @param {Object} isPage   是否加载大于1页
 */
const loadPage=async (options,isPage)=>{
	let ret = await uni.$get('/appapi-opportunity-getmeal',options);
	if(ret.error_code != 0){
		show_main.value=true;
		not_load.value=true;
		uni.$utils.showToast(ret.info,0,()=>{
			uni.navigateBack({data:1});
		});
		return;
	}
	
	show_main.value=true;
	not_load.value=true;
	let list=uni.$utils.twoObj(ret.data.list,2);
	ret.data.list=list;
	result.value=ret.data;
	//console.log(result.value);
};
/**
 * 模板属性跳转页面
 * @param {Object} e
 */
function goPage(event){
	topDropDownShow.value=false;
	uni.$utils.dataSetPage(event);
};
//联系客服
const service=(e)=>{
	let oh_signal = e.currentTarget.dataset.number;
	if(!oh_signal) return;
	let conv=null;
	let uri=null;
	conv=getConversationID(oh_signal);
	/*if(conv.conversationID){
		uri='/pages/chat-single/chat-single?conversationID='+conv.conversationID+'&nick='+conv.userProfile.nick+'&to='+oh_signal;
		uni.$utils.goPage(uri,0);
		return;
	}*/
	not_load.value=false;
	//let str=uni.$appConfig['IM_PREFIX_MAKR']['da_zhao_hu']['rule']+'你好，'+(result.value.virtual_coin_name)+'购买咨询！';
	let str=uni.$appConfig['IM_PREFIX_MAKR']['da_zhao_hu']['rule']+'你好，商机置顶咨询！商机ID号:'+result.value.opportunity.id;
	uni.TIM.createTextMessage(0,oh_signal,str,(data)=>{
		setTimeout(()=>{
			not_load.value=true;
			conv=getConversationID(oh_signal);
			console.log(conv);
			not_load.value=true;
			if(conv.conversationID){
				uri='/pages/chat-single/chat-single?conversationID='+conv.conversationID+'&nick='+conv.userProfile.nick+'&to='+oh_signal;
				uni.$utils.goPage(uri,0);
				return;
			}
		},500)
	});
};
//获取当前用户的会话ID
const getConversationID=(userId)=>{
	let list=uni.$vuex.state.globalData.conversationList;
	for(let i in list){
		if(list[i].type != 'C2C') continue;
		if(list[i].userProfile.userID == userId){
			return list[i];
		}
	}
	return {};
};
//复制
const copy=(e)=>{
	let text=e.currentTarget.dataset.text;
	uni.setClipboardData({
	  data: text,
	  success: function (res) {
	    uni.getClipboardData({
	      success: function (res) {
	        uni.$utils.showToast('复制成功');
	      }
	    })
	  }
	})
};
</script>

<style  lang="scss">
	page {
		
	}
.fnow{color:#2979ff;}
.my_button{
	color:#fff;
	font-weight: normal;
	font-size: 32rpx;
	border:none;
	background: blue;
	background: #2979ff;
}
</style>
